<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
      https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/
      思路：https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/solution/shou-hua-tu-jie-liang-chong-jie-fa-dfshui-su-bfsya/
    */
    let digits = '23';

    function letterCombinations(digits) {
      if (!digits.length) return [];
      let res = [];
      let map = {
        '2': 'abc',
        '3': 'def',
        '4': 'ghi',
        '5': 'jkl',
        '6': 'mno',
        '7': 'pqrs',
        '8': 'tuv',
        '9': 'wxyz'
      }

      function dfs(str, i) {
        if (i > digits.length - 1) {
          res.push(str);
          return;
        }
        for (let l of map[digits[i]]) {
          dfs(str + l, i + 1);
        }
      }
      dfs('', 0);
      return res;
    }
    console.log(letterCombinations(digits));
  </script>
</body>
</html>